home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg1.cab / Currency.xba < prev    next >
Extensible Markup Language  |  2002-11-21  |  6KB  |  178 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Currency" script:language="StarBasic">REM  *****  BASIC  *****
  4. Option Explicit
  5.  
  6. Dim bDoUnLoad as Boolean
  7.  
  8.  
  9. Sub Startup()
  10. Dim i as Integer
  11. Dim a as Integer
  12. Dim ListString as String
  13. Dim MarketListBoxControl as Object
  14.     Initialize(False)
  15.     MarketListBoxControl = DlgStartUp.GetControl("lstMarkets")
  16.     a = 0
  17.     For i = 0 To Ubound(sMarket(),1)
  18.         ListString = sMarket(i,0)
  19.         If sMarket(i,0) <> "" Then
  20.             If sMarket(i,3) = "" Then
  21.                 ListString = ListString & "    (" & sNoInternetUpdate & ")"
  22.             Else
  23.                 ListString = ListString & "    (" & sMarketplace & " " & sMarket(i,2) & ")"
  24.             End If
  25.             MarketListBoxControl.AddItem(ListString, a)
  26.             a = a + 1
  27.         End If
  28.     Next i
  29.     MarketListBoxControl.SelectItemPos(GlobListIndex, True)
  30.     DlgStartUp.Title = sDepotCurrency
  31.     DlgStartUp.Model.cmdGoOn.DefaultButton = True
  32.     DlgStartUp.GetControl("lstMarkets").SetFocus()
  33.     DlgStartUp.Execute()
  34.     DlgStartUp.Dispose()
  35. End Sub
  36.  
  37.  
  38. Sub EnableGoOnButton()
  39.     StartUpModel.cmdGoOn.Enabled = True
  40.     StartUpModel.cmdGoOn.DefaultButton = True
  41. End Sub
  42.  
  43.  
  44. Sub CloseStartUpDialog()
  45.     DlgStartUp.EndExecute()
  46. '    oDocument.Dispose()
  47. End Sub
  48.  
  49.  
  50. Sub DisposeDocument()
  51.     If bDoUnload Then
  52.         oDocument.Dispose()
  53.     End If        
  54. End Sub
  55.  
  56.  
  57. Sub ChooseMarket(Optional aEvent)
  58. Dim Index as Integer
  59. Dim bIsDocLanguage as Boolean
  60. Dim bIsDocCountry as Boolean
  61.     oInternetModel = GetControlModel(oDocument.Sheets(0), "CmdInternet")
  62.     If Not IsMissing(aEvent) Then
  63.         Index = StartupModel.lstMarkets.SelectedItems(0)
  64.         oInternetModel.Tag = Index
  65.     Else
  66.         Index = oInternetModel.Tag
  67.     End If
  68.     oMarketModel = GetControlModel(oDocument.Sheets(0), "CmdHistory")
  69.     sCurCurrency = sMarket(Index,1)
  70.     If Index = 0 Then
  71.         HistoryChartSource = sMarket(Index,4)
  72.     End If
  73.     sCurStockIDLabel = sMarket(Index,5)
  74.     sCurExtension = sMarket(Index,8)
  75.     iValueCol = Val(sMarket(Index,10)
  76.     If Instr(sCurExtension,";") <> 0 Then
  77.         ' Take the german extension as the stock place is Frankfurt
  78.         sCurExtension = "407"
  79.     End If        
  80.     sCurChartSource = sMarket(Index,3)
  81.     bIsDocLanguage = Instr(1, sMarket(Index,6), sDocLanguage, SBBINARY) <> 0
  82.     bIsDocCountry = Instr(1, sMarket(Index,7), sDocCountry, SBBINARY) <> 0  OR SDocCountry = ""
  83.     sCurSeparator = sMarket(Index,9)
  84.     TransactModel.txtRate.CurrencySymbol = sCurCurrency
  85.     TransactModel.txtFix.CurrencySymbol = sCurCurrency
  86.     TransactModel.txtMinimum.CurrencySymbol = sCurCurrency
  87.     bEnableMarket = Index = 0
  88.     bEnableInternet = sCurChartSource <> ""
  89.     oMarketModel.Enabled = bEnableMarket    
  90.     oInternetModel.Enabled = bEnableInternet
  91.     If Not IsMissing(aEvent) Then
  92.         ConvertStylesCurrencies()
  93.         bDoUnload = False
  94.         DlgStartUp.EndExecute()
  95.     End If
  96. End Sub
  97.  
  98.  
  99. Sub ConvertStylesCurrencies()
  100. Dim m as integer
  101. Dim aStyleFormat as Object
  102. Dim StyleName as String
  103. Dim bAddToList as Boolean
  104. Dim oStyle as Object
  105. Dim oStyles as Object
  106.      UnprotectSheets(oSheets)
  107.     oFirstSheet.GetCellByPosition(SBCOLUMNID1, SBROWHEADER1).SetString(sCurStockIDLabel)
  108.     oStyles = oDocument.StyleFamilies.GetbyIndex(0)
  109.     For m = 0 To oStyles.count-1
  110.         oStyle = oStyles.GetbyIndex(m)
  111.         StyleName = oStyle.Name
  112.         bAddToList = CheckFormatType(oStyle)
  113.         If bAddToList Then 
  114.             SwitchNumberFormat(ostyle, oDocFormats, sCurCurrency, sCurExtension)
  115.         End If
  116.     Next m
  117.     ProtectSheets(oSheets)
  118. End Sub
  119.  
  120.  
  121. Sub SwitchNumberFormat(oObject as Object, oFormats as object, sNewSymbol as String, sNewExtension as String)
  122. Dim nFormatLanguage as Integer
  123. Dim nFormatDecimals as Integer
  124. Dim nFormatLeading as Integer
  125. Dim bFormatLeading as Integer
  126. Dim bFormatNegRed as Integer
  127. Dim bFormatThousands as Integer
  128. Dim aNewStr as String
  129. Dim iNumberFormat as Long
  130. Dim sSimpleStr as String
  131. Dim nSimpleKey as Long
  132. Dim aFormat()
  133. Dim oLocale as New com.sun.star.lang.Locale
  134.     ' Numberformat with the new Symbol as Base for new Format
  135.     sSimpleStr = "0 [$" & sNewSymbol & "-" & sNewExtension & "]"
  136.     nSimpleKey = Numberformat(oFormats, sSimpleStr, oDocLocale)
  137.     On Local Error Resume Next
  138.     iNumberFormat = oObject.NumberFormat
  139.     If Err <> 0 Then
  140.         Msgbox "Error Reading the Number Format"
  141.         Resume CLERROR
  142.     End If
  143.  
  144.     On Local Error GoTo NOKEY
  145.     aFormat() = oFormats.getByKey(iNumberFormat)
  146.     On Local Error GoTo 0
  147.     ' set new currency format with according settings
  148.     nFormatDecimals = aFormat.Decimals
  149.     nFormatLeading = aFormat.LeadingZeros
  150.     bFormatNegRed = aFormat.NegativeRed
  151.     bFormatThousands = aFormat.ThousandsSeparator
  152.     oLocale = aFormat.Locale
  153.     aNewStr = oFormats.generateFormat(nSimpleKey, oLocale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
  154.     oObject.NumberFormat = Numberformat(oFormats, aNewStr, oLocale)
  155.     NOKEY:
  156.     If Err <> 0 Then
  157.         Resume CLERROR
  158.     End If
  159.     CLERROR:
  160. End Sub
  161.  
  162.  
  163. Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Variant )
  164. Dim nRetkey 
  165.     nRetKey = oFormats.queryKey(aFormatStr, oLocale, True)
  166.     If nRetKey = -1 Then
  167.         nRetKey = oFormats.addNew( aFormatStr, oLocale )
  168.         If nRetKey = -1 Then nRetKey = 0
  169.     End If
  170.     Numberformat = nRetKey
  171. End Function
  172.  
  173.  
  174. Function CheckFormatType(oStyle as Object)
  175. Dim oFormatofObject as Object
  176.     oFormatofObject = oDocFormats.getByKey(oStyle.NumberFormat)
  177.       CheckFormatType = INT(oFormatOfObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY
  178. End Function</script:module>